The parent pointers from the BFS trace form a tree structure, showing the shortest path from the start node to all others.

  • From the trace, we can populate the final level and parent for each node.
  • The parent pointers define a BFS tree rooted at the start node, s.
  • This tree contains the shortest path (in terms of edge count) from s to every other reachable node.
  • Edges in the original graph that are part of the BFS tree are called tree edges.
  • Other edges, which connect nodes at the same or adjacent levels but aren't part of the shortest path tree, are called non-tree edges.
Vertex (v) parent[v] level[v]
ANIL0
BA1
CA1
DB2
EC2
FB2